<?php

class DefaultClickAction extends FrontendAction
{

    public function __construct()
    {
        parent::__construct();
    }

    public function execute()
    {
        if ($this->data['isRobot'])
        {
            exit;
        }

        $type = 'item';
        $id = $this->context->get('id');
        if (!is_numeric($id))
        {
            $id = $this->context->get('sid');
            $type = 'shop';
        }
        $productService = new ProductService();
//        $productService->setUserId($this->data['user']['id']);
        $info = $productService->getProductById($id);

        if ($info)
        {

            //���µ����¼
            //C('ViewHistoryService')->updateViewHistory($id, 2);


            if ($type == 'shop')
            {
                if ($info['shop_click_url'] != '')
                {
                    //$info['shop_click_url']=str_replace('mm_17538449_0_0', 'mm_28478470_0_0', $info['shop_click_url']);
                    header('Location:' . $info['shop_click_url']);
                    return;
                }
            }
            if ($info['click_url'] != '')
            {
                //$info['click_url']=str_replace('mm_17538449_0_0', 'mm_28478470_0_0', $info['click_url']);
                header('Location:' . $info['click_url']);
                return;
            }
            else
            {
                header('Location:' . $info['item']['detail_url']);
                return;
            }
        }
        header('Location:' . C('LtUrl')->generate('Default', 'Index'));
    }

}
